package com.cip.admin.action;

import java.util.List;
import java.util.Locale;
import java.util.logging.Logger;

import com.cip.admin.service.EmailService;
import com.cip.admin.model.EmailConfig;
import com.cip.master.model.Holiday;
import com.cip.master.model.Section;
import com.cip.admin.model.User;
import com.cip.admin.service.UserManager;
import com.cip.common.util.SecurityUtil;
import com.cip.webapp.action.BaseAction;

public class EmailConfigAction extends  BaseAction {
	private EmailService emailService;
	private EmailConfig emailConfig;
	private List<EmailConfig> emailConfigList;
	
	public String showEmailConfigList() throws Exception {
		
		Locale locale = getRequest().getLocale();
		System.out.println("local===================="+locale);
		String emailConfigString = emailService.getEmailConfigGridList(locale);
		System.out.println("emailConfigString================"+emailConfigString);
				
		getRequest().setAttribute("emailConfigGridString", emailConfigString);
		//setInstituteGridString(instituteString);
				
		
//		setEmailConfigList(emailService.getAllEmaillConfigList());
		return SUCCESS;
	}
	public String showEmailConfigForm() throws Exception{
		setEmailConfig(new EmailConfig());
		return SUCCESS;
	}
	
	public String showEditEmailConfig() {
		try {
			setEmailConfig(emailService.getEmailConfigById(emailConfig.getId()));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}
	public String saveOrUpdateEmailConfig(){
		try
		{
		    User loggedUser = SecurityUtil.getThreadLocalUser().get();
			emailConfig.setTenantId(loggedUser.getTenantId());
			emailService.saveOrUpdateEmailConfig(emailConfig);
	} 
		catch (Exception e) {
		addActionError("Error while adding SMTP Information: "+e.getMessage());
		e.printStackTrace();
	} finally {
          		saveMessage(getText("inbound.added"));
	}
	return SUCCESS;
	}

	

	public EmailService getEmailService() {
		return emailService;
	}
	public void setEmailService(EmailService emailService) {
		this.emailService = emailService;
	}
	public EmailConfig getEmailConfig() {
		return emailConfig;
	}
	public void setEmailConfig(EmailConfig emailConfig) {
		this.emailConfig = emailConfig;
	}
	public List<EmailConfig> getEmailConfigList() {
		return emailConfigList;
	}
	public void setEmailConfigList(List<EmailConfig> emailConfigList) {
		this.emailConfigList = emailConfigList;
	} 
}
